package cn.bdqn.controller;

import cn.bdqn.domain.Dict;
import cn.bdqn.service.DictService;
import cn.bdqn.utils.result.Result;
import cn.bdqn.utils.result.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 字典控制层
 * @author dkj
 */
@RestController
@RequestMapping("/dict")
public class DictController {

    /**
     * 字典业务接口
     */
    @Autowired
    private DictService dictService;

    /**
     * 根据字典类型dicTypeCode查询
     * @param dicTypeCode
     * @return
     */
    @RequestMapping("/queryByDicTypeCode")
    public Result queryByDicTypeCode(String dicTypeCode) throws Exception{
        try {
            //调用根据dicTypeCode类型查询的方法
            List<Dict> dictList = dictService.queryByDicTypeCode(dicTypeCode);
            //返回结果
            return ResultGenerator.genSuccessResult(dictList);
        }catch (Exception e){
            e.printStackTrace();
            throw new Exception(e.getMessage());
        }
    }
}
